package com.github.xaidanwang.data.upload.download.scheduler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author wang yi fei
 * @date 2020/4/16 15:47
 */
@Component
@Configuration
@Slf4j
public class DeleteAllDataJob {
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	@Scheduled(cron = "0 5 5 1/5 * ?")
	public void deleteAllHistoryData(){
		try {
			Set<String> keySet = stringRedisTemplate.keys("**");
			if (keySet == null){
				return;
			}
			log.info("缓存直播间数据总数{}个",keySet.size());
			log.info("删除所有的直播间记录删除{}个,key列表:{}",keySet.size(),keySet);
			stringRedisTemplate.delete(keySet);
		}catch (Exception e){
			log.info("定时任务失败",e);
		}
	}
}
